package com.example.leetcode;

import net.minidev.json.JSONArray;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class LeetCode21 {
    @Test
    public void Test(){
        int[] nums=new int[]{1,2,3,4};
        int[] nums2=exchange(nums);
        for (int i = 0; i < nums2.length; i++) {
            System.out.println(nums2[i]);
        }

    }
    public int[] exchange(int[] nums) {
        int[] num2=new int[nums.length];
        int js=0,ns=nums.length-1;
        for(int i=0;i<nums.length;i++){
            if(nums[i]%2==0){
                num2[ns]=nums[i];
                ns--;
            }else{
                num2[js]=nums[i];
                js++;
            }
        }
        return num2;
    }
}
